#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: 
@time: 2024/2/29 9:58 PM
@Function: 存放login页面对象，每个页面单独进行存放，每个页面的属性维护在data目录下按模块区分
"""
import allure
from playwright.sync_api import Page
from repository import loginObject
from utils.configParse import ConfigParse


class LoginPage:
    def __init__(self, page: Page):
        """
        定义封装页面对象
        :param page:
        """
        self.page = page
        self.username_loc = page.get_by_placeholder(loginObject.username)
        self.password_loc = page.get_by_placeholder(loginObject.password)
        self.submit_loc = page.locator(loginObject.submit)
        self.message_loc = page.locator(loginObject.message)
        self.mobile_login_loc = page.locator(loginObject.mobile_login)
        self.email_login_loc = page.locator(loginObject.email_login)
        self.email_loc = page.locator(loginObject.email)
        self.email_password_loc = page.locator(loginObject.email_password)

    @allure.step("打开登录页面")
    def navigate(self, environment):
        if environment == "test":
            # 测试环境
            self.page.goto(ConfigParse().get_ini_login_url('xbasetest_url'))
        if environment == "stage":
            # stage环境
            self.page.goto(ConfigParse().get_ini_login_url('xbasestage_url'))
        if environment == "prod":
            # 线上环境
            self.page.goto(ConfigParse().get_ini_login_url('xbaseprod_url'))

    @allure.step('点击邮箱登录')
    def email_login_button(self):
        self.email_login_loc.click()

    @allure.step('输入邮箱登录')
    def fill_email_login(self,email_login_info):
        self.email_loc.fill(email_login_info)

    @allure.step('点击手机号登录')
    def mobile_login_button(self):
        self.mobile_login_loc.click()

    @allure.step("输入账号登录")
    def fill_username(self, username_login_info):
        self.username_loc.fill(username_login_info)

    @allure.step("输入密码")
    def fill_password(self, password_login_info):
        self.password_loc.fill(password_login_info)

    @allure.step("点击登录按钮")
    def click_login_button(self):
        self.submit_loc.click()
